import pandas as pd
from common.config import opcUaConfig as Config
import time

'''
输入:valueName:[列表], 附加路径addPath:如果该函数在子工作目录中被调用，addPath传入'../'
输出:valueName 对应的Value:[列表]
'''
def readSysStatusValue(ValueName, addPath=''):
    SysStatus = pd.read_csv(addPath+Config.SysStatus)
    r = []
    for i in range(len(ValueName)):
        index = SysStatus[SysStatus['ValueName']==ValueName[i]].index.item()
        value = SysStatus.loc[index, 'Value']
        r.append(value)
    return r

'''
输入:ValueName:[列表], Value:[列表], 附加路径 addPath
输出: 写入 SysStatus.csv 文件
'''
def writeSysStatusValue(ValueName, Value, addPath=''):
    SysStatus = pd.read_csv(addPath+Config.SysStatus)
    for i in range(len(ValueName)):
        index = SysStatus[SysStatus['ValueName'] == ValueName[i]].index.item()
        SysStatus.loc[index, 'Value'] = Value[i]
        SysStatus.loc[index, 'StartTime'] = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime())
    SysStatus.to_csv(addPath+Config.SysStatus, index=False)

